package com.zx.callback.vo;


import com.zx.callback.common.enums.MessageEnumTable;

import java.io.Serializable;
import java.util.List;

/**
 * Created by nixianjing on 16/5/11.
 */
public class JsonResult<T> implements Serializable {

    private static final long serialVersionUID = -1092992129077237532L;


    private int code;

    private String message;

    private T t;

    private List<T> list;

    public JsonResult() {
    }

    public JsonResult(int code, String message, T t, List<T> list) {
        this.code = code;
        this.message = message;
        this.t = t;
        this.list = list;
    }

    public JsonResult(int code, String message, T t) {
        this.code = code;
        this.message = message;
        this.t = t;
    }


    public JsonResult(int code, String message, List<T> list) {
        this.code = code;
        this.message = message;
        this.list = list;
    }

    public JsonResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public JsonResult(MessageEnumTable messageEnumTable) {
        this.code = messageEnumTable.getCode();
        this.message = messageEnumTable.getMessage();
    }


    public JsonResult(MessageEnumTable messageEnumTable, T t) {
        this.code = messageEnumTable.getCode();
        this.message = messageEnumTable.getMessage();
        this.t = t;
    }

    public static JsonResult getJsonObj(MessageEnumTable messageEnumTable, String... messages) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.code = messageEnumTable.getCode();
        jsonResult.message = MessageEnumTable.getMessage(messageEnumTable.getMessage(), messages);
        return jsonResult;
    }

    public static JsonResult getJsonObj(int code, String message) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.code = code;
        jsonResult.message = message;
        return jsonResult;
    }

    public static JsonResult getOkJsonObj(List<?> list) {
        return new JsonResult(MessageEnumTable.SUCCESS.getCode(), MessageEnumTable.SUCCESS.getMessage(), list);
    }

    public static JsonResult getOkJsonObj(Object object) {
        return new JsonResult(MessageEnumTable.SUCCESS.getCode(), MessageEnumTable.SUCCESS.getMessage(), object);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
